<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <router-link to="/login">点我登录</router-link>
<!--    传递参数-->
    <router-link to="/register/123/yaya">点我注册</router-link>
<!--    显示路由的组件-->
    <router-view></router-view>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!--引入js-->
<script src="https://unpkg.com/vue-router@3.6.5/dist/vue-router.js"></script>

<script>
    //声明组件模板
    const login={
        template:"<h1>用户登录</h1>"
    };
    const register={
        template:"<h1>用户注册</h1>",
        data() {},
        methods: {},
        created() {
            //拿到参数
            alert(this.$route.params.id);
            alert(this.$route.params.name);
        }
    }
    //创建路由对象
    const router=new VueRouter({
        routes:[
            {path:"/",redirect:"/login"},
            //绑定路径和路由对象
            {path:"/login",component:login},
            //绑定变量名和参数
            {path:"/register/:id/:name",component:register}
        ]
    });

    const app = new Vue({
        el: "#app",
        data: {},
        methods: {},
        components: {},
        router:router //绑定路由对象
    })
</script>
</body>
</html>